package com.longge;

public class LongestPalindrome {
    public String longestPalindrome(String s) {

        String res = "";
        String palindrome = "";
        for (int i = 0; i < s.length(); i++) {
            palindrome = palindrome(s, i, i);
            if (res.length() < palindrome.length()) res = palindrome;
            palindrome = palindrome(s, i, i + 1);
            if (res.length() < palindrome.length()) res = palindrome;
        }
        return res;
    }


    public String palindrome(String s, int l, int r) {

        while (l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) {
            l--;
            r++;
        }
        return s.substring(l+1, r);
    }


}
